package cn.ac.iie.di.config;

import cn.ac.iie.di.Reader.Reader;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;

public class ConfigureUtil extends Properties
{
  private static final Logger LOG=Logger.getLogger(Reader.class.getName());
  private static ConfigureUtil conf = new ConfigureUtil();

  public static ConfigureUtil getInstanse(String confPropertiesName) {
    try {
      conf.load(new FileInputStream(new File(confPropertiesName)));
    } catch (Exception ex) {
      LOG.error(new Exception("配置文件位置不对:" + new File(confPropertiesName).getAbsolutePath()).toString());
      LOG.error(new Exception("配置文件位置不对:" + System.getenv("QTLIB")).toString());
    }
    return conf;
  }
  public List<String> getList(String key) {
    return Arrays.asList(getProperty(key).split(","));
  }
  public Integer getInt(String key, String value) {
    return Integer.valueOf(getProperty(key, value));
  }
  public Long getLong(String key, String value) {
    return Long.valueOf(getProperty(key, value));
  }
  public String getString(String key, String value) {
    return getProperty(key, value);
  }
  public Double getDouble(String key, String value) {
    return Double.valueOf(Double.parseDouble(getProperty(key, value)));
  }
  public static void main(String[] args){
      ConfigureUtil config = ConfigureUtil.getInstanse(ConfigureUtil.class.getClassLoader().getResource("longchun.properties").getPath());
      System.out.println(config.getInt("threadnum", "1"));
      System.out.println(config.getInt("queue","1"));
      System.out.println(config.entrySet());
  }
}